

from threading     import Thread #线程
from concurrent.futures import ThreadPoolExecutor #线程池
import time
# def func(name):
#     for i in range(100):
#         print(name,i)


# class MyThread(Thread):
#     def __init__(self, name):
#         super(MyThread,self).__init__()
#         self.name = name
    
#     def run(self):
#         for i in range(1000):
#             print(self.name,i)



# if __name__ == '__main__':
#     # t1 = Thread(target=func,args=("jay",))
#     # t2 = Thread(target=func,args=("jj",))
#     # t3 = Thread(target=func,args=("zrf",))

#     t1 = MyThread(name="jay")
#     t2 = MyThread(name="jj")
#     t3 = MyThread(name="zrf")
#     t1.start()
#     t2.start()
#     t3.start()
#     # func('jay')        
#     # func('was')
#     # func('zrf')
#     print("我是主线程")

# 这是两种写法  一个重写父类   一个简单的for循环


# 下面是线程池
def func(name,sleep):
    time.sleep(sleep)
    # print(name)
    return name
    for i in range(10):
        print(name,i)

def fn(res):
    print(res.result())

if __name__ == '__main__':
    with ThreadPoolExecutor(10) as t:#多线程 的线程池
        # t.submit(func,"name").add_done_callback(fn=fn)#add_done_callback返回值   返回即执行
        # t.submit(func,"xueyin")
        # t.submit(func,"大傻子")

       result = t.map(func,["周杰伦","王富贵","王力宏"],[2,3,1])
       print(result)
       for r in result:
           print(r)

        #map返回的是  生成器  返回的内容和任务分发的顺序是一致的            